Skip to content

add python bindings for all kernels - #65

Merged
ngc92 merged 18 commits into
devfrom
pybind
Mar 1, 2026
Merged

ngc92 merged 18 commits into
devfrom
pybind

Conversation

@ngc92

@ngc92 ngc92 commented Mar 1, 2026

Copy link
Copy Markdown
Collaborator

Add python bindings for all kernels so we can more easily test them.

Copilot AI review requested due to automatic review settings March 1, 2026 18:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a comprehensive Python testing surface for the CUDA kernels by introducing nanobind-based bindings, a Python convenience wrapper layer, and a large pytest suite to validate kernel correctness and determinism.

Changes:

  • Added a new nanobind binding layer (kernel_binding.cpp + binding_utils.*) and wired it into the _pyllmq module build.
  • Improved error reporting across tensor dtype accessors and kernel dispatch wrappers (more informative unsupported-dtype / shape mismatch errors).
  • Added Python torch.library.custom_op wrappers and a large CUDA pytest suite to exercise the bound kernels.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/utilities/tensor.h Routes dtype mismatches through a helper function (but keeps constexpr accessors).
src/utilities/tensor.cpp Implements throw_dtype_mismatch with a detailed message.
src/utilities/dtype.cpp Accepts additional string aliases for FP8 dtype parsing.
src/kernels/swiglu.cu Replaces asserts with runtime argument validation + safer size checks.
src/kernels/kernels.cpp Centralizes “unsupported dtype” errors with dtype reporting for multiple tensors.
src/kernels/global_norm.cu Minor formatting change to kernel launch.
src/kernels/encoder.cu Updates vector load/store helpers and re-enables a kernel call.
src/kernels/bias.cu Adds runtime validation for OC vectorization and improves exception type.
src/kernels/adamw.cu Adds runtime validation for vectorization constraints.
src/binding/python/kernels.py Python wrappers registering custom ops that call into _pyllmq.
src/binding/kernel_binding.cpp New nanobind wrappers for most kernels (shape/dtype/device validation + argument extraction).
src/binding/binding_utils.h / .cpp New shared utilities for dlpack dtype conversion and ndim checks.
src/binding/binding.cpp Integrates the new kernel registration entrypoint.
scripts/test_kernels.py Adds pytest coverage for many kernels (forward/backward, determinism, correctness).
CMakeLists.txt Updates nanobind version and adds new binding sources to the Python module build.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/utilities/tensor.h Resolved
Comment thread src/binding/kernel_binding.cpp Resolved
Comment thread src/binding/kernel_binding.cpp Resolved
Comment thread src/binding/kernel_binding.cpp Resolved
Comment thread src/binding/kernel_binding.cpp Resolved
Comment thread scripts/test_kernels.py Resolved
Comment thread CMakeLists.txt Resolved
Copilot AI review requested due to automatic review settings March 1, 2026 18:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 16 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/kernels/kernels.cpp Resolved
Comment thread src/binding/binding_utils.cpp Resolved
Comment thread src/binding/kernel_binding.cpp Resolved
@ngc92
ngc92 merged commit fcb6292 into dev Mar 1, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants